package com.hitqz.robot.driver.listener;

import com.hitqz.robot.api.business.enums.FormConfigEnum;
import com.hitqz.robot.api.business.enums.RobotParamsFormFieldEnum;
import com.hitqz.robot.api.business.event.FormUpdateEvent;
import com.hitqz.robot.api.common.dto.form.FormFieldConfigUpdateDto;
import com.hitqz.robot.driver.communication.NetworkServiceThreadPool;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

@Component
@AllArgsConstructor
@Slf4j
public class GfParamsListener {

    @EventListener
    public void onParamsUpdate(FormUpdateEvent event) {
        NetworkServiceThreadPool.dealEvent(() -> {
            String formName = event.getFormName();
            if (!Objects.equals(formName, FormConfigEnum.ROBOT_PARAMS_CONFIG.getFormName())) {
                return;
            }
            List<FormFieldConfigUpdateDto> fields = event.getUpdateFields();
            this.updateRobotParams(fields);
            log.info("[gf]机器人参数配置更新");
        });
    }


    private void updateRobotParams(List<FormFieldConfigUpdateDto> fields) {
        if (fields.isEmpty()) {
            return;
        }
        for (FormFieldConfigUpdateDto field : fields) {
            String name = field.getFieldName();
            // 传感器使能

        }
    }


}
